#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 'tyh'
__mtime__ = '18-9-14'
# code is far away from bugs with the god animal protecting ~
"""
from functools import wraps
from flask import session, g, jsonify
from werkzeug.routing import BaseConverter

from info.response_code import error_map


def required_login(func):
	@wraps(func)
	def wrapper(*args, **kwargs):
		user_id = session.get("user_id", None)
		user = None
		if user_id:
			from info.models import User
			user = User.query.get(user_id)
		g.user = user
		return func(*args, **kwargs)
	return wrapper

def filter_series(series):
	if series == 1 :
		return "first"
	elif series == 2 :
		return "second"
	elif series == 3 :
		return "third"
	else:
		return None

def general_msg(code,msg=None):
	if msg:
		errmsg = error_map[code] + "-" + str(msg)
	else:
		errmsg = error_map[code]
	error_msg = {"errno": code, "errmsg": errmsg}
	return jsonify(error_msg)


class RegexConverter(BaseConverter):
	def __init__(self, url_map, *args):
		super(RegexConverter, self).__init__(url_map)
		# 将接受的第1个参数当作匹配规则进行保存
		self.regex = args[0]


if __name__ == '__main__':
	pass